package chapter5.homework.GeometryCalc;

import java.util.InputMismatchException;
import java.util.Scanner;

class Rectangle {
    public static int getCounter() {
        return counter;
    }

    static int counter;

    static void count() {

        counter++;
    }

    double length;
    double width;

    protected static boolean calc(){
        double length,width;
        Scanner scanner=new Scanner(System.in);
        Rectangle rectangle=null;
        while (true){
            try{
                length = scanner.nextDouble();
                System.out.println("请输入宽");
                width = scanner.nextDouble();
                if (test(length, width)) {
                    rectangle=new Rectangle(length,width);
                    rectangle.showResult();
                    count();
                    return true;
                }
                else {
                    System.out.println("长宽输入无效");
                }
            }
            catch (InputMismatchException ime){
                System.out.println("请输入数字！");
                continue;
            }
        }


    }
    static boolean test(double length,double width){
        if(length<width)return false;
        else if(length<=0)return false;
        else if(width<=0)return false;
        else return true;
    }
    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }
    public Rectangle(){
        this(0,0);
    }

    double S() {
        return this.width * this.length;
    }
    double C(){
        return 2*(this.length+this.width);

    }
    void showResult(){
        System.out.println("该矩形周长：\t"+this.C());
        System.out.println("面积\t\t"+this.S());
    }
}
